package com.danskin.wechat.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.danskin.wechat.dao.CustFeedbackDao;
import com.danskin.wechat.dao.CustInfoDao;
import com.danskin.wechat.entity.CustFeedback;
import com.danskin.wechat.service.CustFeedbackService;
import com.danskin.wechat.util.ConvertUtils;
import com.danskin.wechat.util.Page;
@Service
public class CustFeedbackServiceImpl implements CustFeedbackService {

	@Autowired
	private CustFeedbackDao custFeedbackDao;
	
	@Autowired
	private CustInfoDao custInfoDao;

	@Override
	public int saveCustFeedbackSelective(CustFeedback custFeedback, String OpenId) {
		
		Map<String, Object> map = custInfoDao.queryByOpenId(OpenId);
		int i=0;
		if(null!=map){
			String mid=map.get("mpId").toString();
			String cust_ex_id=String.valueOf(map.get("cust_ex_id"));
			int mpId = ConvertUtils.getInt(mid);
			int custExId=ConvertUtils.getInt(cust_ex_id);
			custFeedback.setMpId(mpId);
			custFeedback.setCustExId(custExId);
			i=custFeedbackDao.insertSelective(custFeedback);
		}
		return i;
	}

	@Override
	public List<CustFeedback> listPageGetCustFeedback(Page page) {
		List<CustFeedback> list = custFeedbackDao.listPageGetCustFeedback(page);
		return list;
	}

	@Override
	public int deleteCustFeedbackById(Integer id) {
		int deleteByPrimaryKey = custFeedbackDao.deleteByPrimaryKey(id);
		return deleteByPrimaryKey;
	}

	@Override
	public int updateCustFeedbackById(Integer id) {
		CustFeedback custFeedback=new CustFeedback();
		custFeedback.setId(id);
		custFeedback.setStatus(1);
		int i = custFeedbackDao.updateByPrimaryKeySelective(custFeedback);
		return i;
	}

}
